package com.autonavi.yunda.yunji.core.model.condition;

import com.autonavi.yunda.yunji.core.enums.FunctionStatus;
import com.autonavi.yunda.yunji.core.enums.FunctionType;
import com.autonavi.yunda.yunji.core.model.dto.FunctionConfigDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author sunzhenbang
 * @date 2022/08/09
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FunctionQueryCondition {
    private Long id;
    private String projectId;
    private String name;
    private String likeName;
    private List<String> names;
    private String description;
    private FunctionType type;
    private FunctionStatus status;
    private String version;
    private Set<Long> ids = new HashSet<>();

    public Integer pageNo;
    public Integer pageSize;

    public LambdaQueryWrapper<FunctionConfigDTO> toQueryWrapper() {
        LambdaQueryWrapper<FunctionConfigDTO> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(ids != null, FunctionConfigDTO::getId, ids);
        queryWrapper.eq(status != null, FunctionConfigDTO::getStatus, status);
        queryWrapper.eq(type != null, FunctionConfigDTO::getType, type);
        queryWrapper.like(StringUtils.isNotBlank(description), FunctionConfigDTO::getDescription, description);
        queryWrapper.eq(StringUtils.isNotBlank(name), FunctionConfigDTO::getName, name);
        queryWrapper.like(StringUtils.isNotBlank(likeName), FunctionConfigDTO::getName, likeName);
        queryWrapper.eq(StringUtils.isNotBlank(version), FunctionConfigDTO::getVersion, version);
        return queryWrapper;
    }
}

